package com.yanqu.road.server.manager.unionwar.sort;

import com.yanqu.road.entity.activity.unionwar.cross.CrossUnionWarSimple;
import com.yanqu.road.server.manager.unionwar.CrossUnionWarMgr;

import java.util.Comparator;

public class UnionWarSortByScore2 implements Comparator<UnionWarSortEntity> {

    private int activityId;

    public UnionWarSortByScore2(int activityId) {
        this.activityId = activityId;
    }

    @Override
    public int compare(UnionWarSortEntity first, UnionWarSortEntity two) {
        CrossUnionWarSimple firstUnion = CrossUnionWarMgr.getCrossUnionWarSimple(activityId, first.unionUid);
        CrossUnionWarSimple twoUnion = CrossUnionWarMgr.getCrossUnionWarSimple(activityId, two.unionUid);
        if(firstUnion == null){
            return 1;
        }
        if(twoUnion == null){
            return -1;
        }
        if(firstUnion.getScore2() > twoUnion.getScore2()){
            return -1;
        }
        if(firstUnion.getScore2() < twoUnion.getScore2()){
            return 1;
        }
        if(firstUnion.getUnionBaseInfo().getTotalEarnSpeed().compareTo(twoUnion.getUnionBaseInfo().getTotalEarnSpeed()) > 0){
            return -1;
        }
        if(firstUnion.getUnionBaseInfo().getTotalEarnSpeed().compareTo(twoUnion.getUnionBaseInfo().getTotalEarnSpeed()) < 0){
            return 1;
        }
        return 0;
    }
}
